package com.huobao.shangjia_version.activitys;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.huobao.yunying.activitys.Act_Edit_Msg;
import com.huobao.yunying.activitys.Act_Manager_Pwd;
import com.huobao.yunying.activitys_store.Act_Store;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.yunying.utils.ShareUtils;
import com.huobao.yunying.utils.Utils;
import com.huobao.zhangying.R;

import org.xutils.view.annotation.ViewInject;

public class Act_MyStore extends HuobaoBaseActivity implements OnClickListener {
	private LinearLayout llyt;
	private ImageView imageview;
	private TextView tv_1;
	private TextView tv_2;
	private TextView tv_3;
	private TextView tv_4;
	private LinearLayout llyt_1;
	private LinearLayout llyt_2;
	private LinearLayout llyt_3;
	private LinearLayout llyt_4;

	private String store_img, store_id;
	
	
	
	
	@ViewInject(R.id.view_clear_cacle)
    private View view_clear_cacle;
    @ViewInject(R.id.tv_huancun)
    private TextView tv_huancun;
    @ViewInject(R.id.view_update)
    private View view_update;
    @ViewInject(R.id.tv_banben)
    private TextView tv_banben;
    @ViewInject(R.id.view_pingfen)
    private View view_pingfen;

	@Override
	protected int getContentView() {
		return R.layout.layout_mystore;
	}

	@Override
	protected String getTitleText() {
		return getString(R.string.title_3);
	}

	@Override
	protected void init() {
		store_img = getIntent().getStringExtra("img");
		store_id = getIntent().getStringExtra("id");
		
		view_clear_cacle.setOnClickListener(this);
		view_update.setOnClickListener(this);
		view_pingfen.setOnClickListener(this);
		tv_huancun.setText(ImageUtils.getCacelSize());
		tv_banben.setText(Utils.getAppVersionName(context));
		initView();
	}

	private void initView() {
		llyt = (LinearLayout) findViewById(R.id.llyt);
		imageview = (ImageView) findViewById(R.id.imageview);
		tv_1 = (TextView) findViewById(R.id.tv_1);
		tv_2 = (TextView) findViewById(R.id.tv_2);
		tv_3 = (TextView) findViewById(R.id.tv_3);
		tv_4 = (TextView) findViewById(R.id.tv_4);
		llyt_1 = (LinearLayout) findViewById(R.id.llyt_1);
		llyt_2 = (LinearLayout) findViewById(R.id.llyt_2);
		llyt_3 = (LinearLayout) findViewById(R.id.llyt_3);
		llyt_4 = (LinearLayout) findViewById(R.id.llyt_4);
		llyt.setOnClickListener(this);
		tv_1.setOnClickListener(this);
		tv_2.setOnClickListener(this);
		tv_3.setOnClickListener(this);
		tv_4.setOnClickListener(this);
		llyt_1.setOnClickListener(this);
		llyt_2.setOnClickListener(this);
		llyt_3.setOnClickListener(this);
		llyt_4.setOnClickListener(this);
		ImageUtils.loadimg(imageview, store_img);

	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent();
		switch (v.getId()) {
		case R.id.llyt:
			intent.setClass(context, Act_Base_Setting.class);
			intent.putExtra("img", store_img);
			startActivity(intent);
			break;
		case R.id.tv_1:
			intent.setClass(context, Act_Edit_Msg.class);
			intent.putExtra("flag", true);
			intent.putExtra("img", store_img);
			startActivity(intent);

			break;
		case R.id.tv_2:
			intent.setClass(context, Act_Store_share.class);
			startActivity(intent);
			break;
		case R.id.tv_3:
			ShareUtils.showShare(this, "http://m.zhangyingtianxia.com/index.php?app=store&id="+store_id);
			break;
		case R.id.tv_4:
			intent.setClass(context, Act_Store.class);
			intent.putExtra("id", store_id);
			startActivity(intent);
			break;
		case R.id.llyt_1:
			intent.setClass(context, Act_Zijin_Manager.class);
			intent.putExtra("epay_dj", getIntent().getStringExtra("epay_dj"));
			intent.putExtra("epay_money", getIntent().getStringExtra("epay_money"));
			startActivity(intent);
			break;
		case R.id.llyt_2:
			intent.setClass(context, Act_Manager_Pwd.class);
			intent.putExtra("flag", true);
			startActivity(intent);
			break;
		case R.id.llyt_3:
			break;
		case R.id.llyt_4://实名认证
			intent.setClass(context, Act_Renzheng_List.class);
			startActivity(intent);
			break;
		case R.id.view_clear_cacle:
			ImageUtils.clearCache();
			Toast.makeText(context, getString(R.string.text2), Toast.LENGTH_SHORT).show();
			tv_huancun.setText(ImageUtils.getCacelSize());
			break;
		case R.id.view_update:
			checkUpdate();
			break;
		case R.id.view_pingfen:
			Uri uri = Uri.parse("market://details?id="+getPackageName());    
			intent = new Intent(Intent.ACTION_VIEW,uri);    
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
			startActivity(intent);    
			break;
		}
	}
	private void checkUpdate(){
		Utils.checkUpdate(this, true);
	}
	@Override
	protected boolean getCheckShowMsg() {
		return true;
	}
}
